/*
 * Copyright (C) 2019-2020 Alibaba Group Holding Limited
 */

// #include <soc.h>
#include <sys/time.h>
#include <time.h>
#include <csi_core.h>

#include <aos/kernel.h>
#include <errno.h>
int clock_settime(clockid_t clockid, const struct timespec *tp)
{
	uint64_t time_ms = 0;

    /* only CLOCK_REALTIME can be set */
    if ((clockid != CLOCK_REALTIME) || (tp == NULL) ||
        (tp->tv_nsec < 0) || (tp->tv_nsec >= 1000000000UL)) {
        errno = EINVAL;
        return -1;
    }

    time_ms = (tp->tv_sec * 1000) + (tp->tv_nsec / 1000000);
    aos_calendar_time_set(time_ms);

    return 0;
}
